package com.wgts.wgts.control.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wgts.wgts.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *   data:2018/9/269:48
 *
 */public class CancelListAdapter extends RecyclerView.Adapter<CancelListAdapter.ViewHold> {
    private Context context;
    private List<String> list;
    private onItemClickListen onItemClickListen;

    public CancelListAdapter(Context context, List<String> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate
                (R.layout.dialog_fragment_cancle_list_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHold viewHold, final int i) {
        viewHold.cancelDialogItemText.setText(list.get(i));
        viewHold.cancelDialogItemLy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListen != null){
                    onItemClickListen.onItemClick(viewHold.cancelDialogItemLy, i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.cancel_dialog_item_text)
        TextView cancelDialogItemText;
        @BindView(R.id.cancel_dialog_item_ly)
        LinearLayout cancelDialogItemLy;

        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface onItemClickListen {
        void onItemClick(View view, int position);
    }

    public void setOnItemClickListen(onItemClickListen onItemClickListen) {
        this.onItemClickListen = onItemClickListen;
    }
}
